Ext.define('TS.lib.form.Combo', {
    extend: 'Ext.form.field.ComboBox',
    alias : 'widget.combo',
	anchor: '95%',
	applyListeners:function(){
		var match = Util.attrMatch(this.initialConfig,'on%');
		for(x in match){
			typeof match[x] === 'function' &&
				this.on(x.substr(2).toLowerCase(),match[x]);
		}
		var match = Util.attrMatch(this.initialConfig,'before%');
		for(x in match){
			typeof match[x] === 'function' &&
				this.on(x.toLowerCase(),match[x]);
		}
		//this.initialConfig.beforeSelect && this.on('beforeselect',this.initialConfig.beforeSelect);
	},
	initComponent:function(){	
		this.emptyText = this.initialConfig.empty || this.initialConfig.emptyText;
		this.allowBlank = this.initialConfig.b || this.initialConfig.allowBlank;
		this.listConfig.emptyText = this.initialConfig.empty;
		
		this.on('specialkey', function(f,o){
			if(o.keyCode == 13){
				var fn = this.initialConfig.enter || this.initialConfig.onEnter;
				if(typeof fn === 'function'){
					Ext.Function.defer(fn,100);
				} else if(fn){
					if(fn.indexOf('->')>0){
						var fld = fn.split('->')[1],
							place = fn.split('->')[0];
					} else {
						var fld = fn, place = null;
					}
					Ext.Function.defer(Util.fireButton(fld,place),100);
				}
			}
		});
		
		this.initialConfig.allowRaw || this.on('blur',this.clearOnBlur);
		
		this.applyListeners();
		
		this.callParent(arguments);
	},
	blankText:'To pole jest wymagane.',
	enableKeyEvents:true,
	hideMode:'offsets',
	queryMode:'local',
	valueField:'id',// TODO ? potzrebne?
	displayField:'name',
	queryDelay:10,
	forceSelection:false,
	//typeAhead:true, ~// out bo wkurza!
	selectOnFocus: true,
	triggerAction:'all',
	minChars:1,
	//allowBlank:false,
	listConfig:{
		//cls:C.listClass || '' ,
		//width: !Ext.isIE  ? 'auto' : null,
		width:'auto',
		//resizable:true,
		emptyText:'',
		loadingText:'Wczytywanie...'//,
		//minWidth: 200
	},
	clearOnBlur:function(fld){
		if(fld.getValue() == fld.getRawValue()){// czyscimy jesli pusta wartosc niepasuje 
			var items = fld.getStore().data.items,
				test = Util.search(items,'internalId',fld.getValue());
			if(test===false){
				fld.clearValue();
			} else if(test.data.name !== fld.getRawValue()){
				fld.setRawValue(test.data.name);
			}
		}
	}
});
    